#ifndef ENGINE_H
#define ENGINE_H
#include <disable_stupid_warnings.h>
#include <QDebug>
#include <QObject>
#include <QVector>
#include <index.hpp>
#include <parameter.hpp>
#include <eigen3/Eigen/Eigen>
#include <QMetaType>
Q_DECLARE_METATYPE(QVector<double>)

using namespace Eigen;
class Engine : public QObject
{
    Q_OBJECT
public:
    Engine(QObject *parent = nullptr);
signals:
    void prepared(bool ok);
    void finished(bool ok);
    void stepFinished(bool ok, int curStep, QVector<double> data);
public slots:
    void init();
    void next();
    void unInit();
    void jumpToStart();
    void prepare(bool ok);
    void setParameter(const Parameter parm);
private:
    bool m_prepared;

    //这下面三个东西没卵用，只是用于内存对齐的，不然有的编译器会给warning
    bool uselesspadding1;
    bool uselesspadding2;
    bool uselesspadding3;

    int m_currentStep;
    Parameter m_parm;
    QVector<double> m_cache;
    VectorXd m_tFirst,m_tSecond;
    SparseLU<SparseMatrix<double>> m_lu;

    bool initLUSolver();
    void copyToQVector(const VectorXd vec, QVector<double> & qvec);
};


#endif // ENGINE_H
